package com.tlsc;

import cn.hutool.core.lang.TypeReference;
import cn.hutool.json.JSONUtil;
import com.deepoove.poi.XWPFTemplate;
import com.tlsc.model.TestAModel;
import com.tlsc.model.TestBModel;
import com.tlsc.model.TestCModel;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @note:
 * @author: HuangXueJi
 * @date: 2025/5/9
 **/
public class Main2 {
    public static void main(String[] args) {

        System.out.println("Hello world!");
        TestAModel testAModel = new TestAModel();
        testAModel.setName("Huang You");
        testAModel.setAge(18);
        testAModel.setBirthday(new Date());

        String picUrl="http://192.168.1.140:8066/tly-java/UploadFiles/20250327/7ec56778-877d-4b96-af3f-9a2f41ffd84c/.jpg/caf41cc3-87b0-4f46-9a77-8a43c7d6b15f.jpg_100x100.jpg";
        List<TestBModel> testBList = new ArrayList<>();
        TestBModel testBModel = new TestBModel();
        testBModel.setName("TestBName  1111");
        List<TestCModel> testCList = new ArrayList<>();
        TestCModel testCModel = new TestCModel();
        testCModel.setName("TestCName  1111");
        testCModel.setPicUrl(picUrl);
        testCList.add(testCModel);

        TestCModel testCModel2 = new TestCModel();
        testCModel2.setName("TestCName  2222");
        testCModel2.setPicUrl(picUrl);
        testCList.add(testCModel2);
        testBModel.setTestCList(testCList);
        testBList.add(testBModel);

        TestBModel testBModel2 = new TestBModel();
        testBModel2.setName("TestBName  2222");
        List<TestCModel> testCList2 = new ArrayList<>();
        TestCModel testCModel3 = new TestCModel();
        testCModel3.setName("TestCName  3333");
        testCModel3.setPicUrl(picUrl);
        testCList2.add(testCModel3);
        testBModel2.setTestCList(testCList2);
        testBList.add(testBModel2);
        testAModel.setTestBList(testBList);

       // Map<String, Object> map = JSONUtil.parseObj(testAModel).toBean(new TypeReference<Map<String, Object>>() {});
        Map<String, Object> map = JSONUtil.toBean(JSONUtil.toJsonStr(testAModel), Map.class);
        XWPFTemplate template = XWPFTemplate.compile("D:\\javaCode\\java-poi-tl-demo\\source\\poi-tl-word\\src\\main\\resources\\test.docx")
                .render(map);

        try {
            template.writeAndClose(new FileOutputStream("output.docx"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}